import os
import json
import random
import re
import math
import datetime
import time
import asyncio
from botpy.message import GroupMessage
from tools import send_message, player_id, player_name, player_number, player_read, player_write, txt_write, txt_exist, bag_add, bag_reduce, bag_enough


async def do_enchant(message):
    if hasattr(message.author, 'member_openid'):
        number = message.author.member_openid
    elif hasattr(message.author, 'user_openid'):
        number = message.author.user_openid
    uid = await player_id(number)
    play_name = await player_name(uid)
    jobs = await player_read(number, "副职业", None)
    if not any(job["副职业"] == "锻造师" for job in jobs):
        if_job = False
        txt = "\n【你不具备锻造条件！】"
        await send_message(message, 0, 1, txt)
        return
    else:
        if_job = True
        job_level = int([job["等级"] for job in jobs if job["副职业"] == "锻造师"][0])

    whole_name = message.content.split("附魔")[1]
    equip_split = whole_name.split("*")
    if len(equip_split) < 3:
        txt = "\n【附魔格式错误！】\n示例：[附魔木棍*白晶*1*拟名]"
        await send_message(message, 0, 1, txt)
        return
    elif len(equip_split) == 3 and "·" not in equip_split[0]:
        txt = "\n【附魔格式错误！】\n【装备未拟名！】\n示例：[附魔木棍*白晶*1*拟名]"
        await send_message(message, 0, 1, txt)
        return
    elif len(equip_split) == 4 and "·" in equip_split[0]:
        txt = "\n【附魔格式错误！】\n【装备已冠名！】\n示例：[附魔木棍·疾风*白晶*1]"
        await send_message(message, 0, 1, txt)
        return
    equip_name = equip_split[0]
    stone_name = equip_split[1]
    stone_number = int(equip_split[2])
    
    if len(equip_split) == 4:
        equip_given = equip_split[3]
        with open(f"data/冠名.txt", 'r') as f:
            given_data = json.load(f)
        if equip_given in given_data:
            txt = "\n【拟名重复！】\n示例：[附魔木棍*白晶*1*拟名]".format(equip_name)
            await send_message(message, 0, 1, txt)
            return
        if not equip_given.isalpha():
            txt = "\n【拟名不得含有空格字符！】\n示例：[附魔木棍*白晶*1*拟名]".format(equip_name)
            await send_message(message, 0, 1, txt)
            return

    if "不够" in await bag_enough(uid, stone_name, stone_number):
        txt = "\n【你没有足够的[{}]！】".format(stone_name)
        await send_message(message, 0, 1, txt)
        return
    with open(f"data/bag/{uid}.txt", 'r') as f:
        data = json.load(f)
    have_equip = False
    for item in data['背包']:
        item_name = item['名称'].split("+")[0]
        true_equip_name = item_name.split("·")[0]
        if item_name == equip_name:
            whole_equip_name = item['名称']
            item['数量'] = int(item['数量']) - 1
            if item['数量'] <= 0:
                data['背包'].remove(item)
            have_equip = True
            break

    if not have_equip:
        txt = "\n【你背包中不存在[{}]】".format(equip_name)
        await send_message(message, 0, 1, txt)
        return

    if not os.path.exists(f"data/equipment/{true_equip_name}.txt"):
        txt = "\n【[{}]不可锻造！】".format(true_equip_name)
        await send_message(message, 0, 1, txt)
        return
    with open(f"data/equipment/{true_equip_name}.txt", 'r') as f:
        equip_data = json.load(f)
    total_score = 0
    score_list = {"最大生命": 1, "最大魔力": 1, "生命": 1, "魔力": 1, "物攻": 4, "魔攻": 4, "物防": 2, "魔防": 2, "命中": 2, "闪避": 2, "暴击": 2, "暴伤": 2, "暴免": 2, "暴抗": 2, "韧性": 2, "速度": 2, "体质": 120, "敏捷": 120, "力量": 120, "智力": 120, "物理减伤": 0, "魔法减伤": 0, "物理赠伤": 0, "魔法赠伤": 0}
    for key, value in equip_data["属性"].items():
        total_score += int(score_list[key] * value)

    if stone_name == "白晶":
        stone_term = {"生命": 100, "魔力": 100, "物攻": 25, "魔攻": 25, "物防": 25, "魔防": 25, "命中": 50, "闪避": 50, "暴击": 50, "暴伤": 50, "暴免": 50, "暴抗": 50, "韧性": 50, "速度": 50}
        stont_add_percent = [1, 0.25, 0, 0, 0, 0]
    if stone_name == "绿晶":
        stone_term = {"生命": 200, "魔力": 200, "物攻": 50, "魔攻": 50, "物防": 50, "魔防": 50, "命中": 100, "闪避": 100, "暴击": 100, "暴伤": 100, "暴免": 100, "暴抗": 100, "韧性": 100, "速度": 100}
        stont_add_percent = [1, 0.35, 0.05, 0, 0, 0]
    if stone_name == "劣等角质":
        stone_term = {"生命": 160, "物防": 40, "暴免": 80, "暴抗": 80, "体质": 2}
        stont_add_percent = [1, 0, 0, 0, 0, 0]
    if stone_name == "劣等硬刺":
        stone_term = {"物攻": 40, "暴击": 80, "暴伤": 80, "命中": 80, "力量": 2}
        stont_add_percent = [1, 0, 0, 0, 0, 0]
    if stone_name == "角质":
        stone_term = {"生命": 320, "物防": 80, "暴免": 160, "暴抗": 160, "体质": 4}
        stont_add_percent = [1, 0, 0, 0, 0, 0]
    if stone_name == "硬刺":
        stone_term = {"物攻": 80, "暴击": 160, "暴伤": 160, "命中": 160, "力量": 4}
        stont_add_percent = [1, 0, 0, 0, 0, 0]
    if stone_name == "上等角质":
        stone_term = {"生命": 600, "物防": 150, "暴免": 300, "暴抗": 300, "体质": 3}
        stont_add_percent = [1, 0, 0, 0, 0, 0]
    if stone_name == "上等硬刺":
        stone_term = {"物攻": 150, "暴击": 300, "暴伤": 300, "命中": 300, "力量": 3}
        stont_add_percent = [1, 0, 0, 0, 0, 0]
    if stone_name == "蓝晶":
        stone_term = {"生命": 400, "魔力": 400, "物攻": 100, "魔攻": 100, "物防": 100, "魔防": 100, "命中": 200, "闪避": 200, "暴击": 200, "暴伤": 200, "暴免": 200, "暴抗": 200, "韧性": 200, "速度": 200, "体质": 3, "敏捷": 3, "力量": 3, "智力": 3}
        stont_add_percent = [1, 0.5, 0.15, 0, 0, 0]
    if stone_name == "紫晶":
        stone_term = {"生命": 800, "魔力": 800, "物攻": 200, "魔攻": 200, "物防": 200, "魔防": 200, "命中": 400, "闪避": 400, "暴击": 400, "暴伤": 400, "暴免": 400, "暴抗": 400, "韧性": 400, "速度": 400, "体质": 6, "敏捷": 6, "力量": 6, "智力": 6}
        stont_add_percent = [1, 0.75, 0.4, 0.05, 0, 0]
    if stone_name == "金晶":
        stone_term = {"生命": 1600, "魔力": 1600, "物攻": 400, "魔攻": 400, "物防": 400, "魔防": 400, "命中": 800, "闪避": 800, "暴击": 800, "暴伤": 800, "暴免": 800, "暴抗": 800, "韧性": 800, "速度": 800, "体质": 12, "敏捷": 12, "力量": 12, "智力": 12}
        stont_add_percent = [1, 1, 0.6, 0.15, 0, 0]
    if stone_name == "红晶":
        stone_term = {"生命": 3200, "魔力": 3200, "物攻": 800, "魔攻": 800, "物防": 800, "魔防": 800, "命中": 1600, "闪避": 1600, "暴击": 1600, "暴伤": 1600, "暴免": 1600, "暴抗": 1600, "韧性": 1600, "速度": 1600, "体质": 25, "敏捷": 25, "力量": 25, "智力": 25}
        stont_add_percent = [1, 1, 0.75, 0.25, 0.03, 0]
    if stone_name == "彩晶":
        stone_term = {"生命": 10000, "魔力": 10000, "物攻": 2500, "魔攻": 2500, "物防": 2500, "魔防": 2500, "命中": 5000, "闪避": 5000, "暴击": 5000, "暴伤": 5000, "暴免": 5000, "暴抗": 5000, "韧性": 5000, "速度": 5000, "体质": 80, "敏捷": 80, "力量": 80, "智力": 80}
        stont_add_percent = [1, 1, 1, 0.5, 0.1, 0]
    key, value = random.choice(list(stone_term.items()))
    max_value = 0
    for i in range(stone_number):
        num = int(random.randint(1, value) * (1 + 0.03 * job_level))
        if num > max_value:
            max_value = num
        if max_value > int(total_score / score_list[key] / 4):
            max_value = int(total_score / score_list[key] / 4)

    equip_add_name = key
    equip_add_value = max_value


    if len(equip_split) == 3:
        equip_have = whole_equip_name.split("=")
        if len(equip_have) != 3:
            txt = "\n【装备数据错误！】"
            await send_message(message, 0, 1, txt)
            return
        equip_have_split = equip_have[1].split("&")
        equip_have_number = len(equip_have_split)
        equip_add_percent = stont_add_percent[equip_have_number - 1]
        if random.random() <= equip_add_percent:
            for random_num in range(1, equip_have_number):
                txt0 = "\n◈[{}+{}]".format((equip_have_split[random_num - 1].split("*"))[0], (equip_have_split[random_num - 1].split("*"))[1])
            new_equip_name = "{}={}{}*{}&={}".format(equip_have[0], equip_have[1], equip_add_name, equip_add_value, equip_have[2])
            txt0 += "\n◈新增[{}+{}]".format(equip_add_name, equip_add_value)
        else:
            txt0 = ""
            for random_num in range(1, equip_have_number):
                txt0 += "\n◈[{}+{}]➡︎[{}+{}]".format((equip_have_split[random_num - 1].split("*"))[0], (equip_have_split[random_num - 1].split("*"))[1], equip_add_name, equip_add_value)
                equip_have_split[random_num - 1] = "{}*{}".format(equip_add_name, equip_add_value)
                key, value = random.choice(list(stone_term.items()))
                max_value = 0
                for i in range(stone_number):
                    num = int(random.randint(1, value) * (1 + 0.03 * job_level))
                    if num > max_value:
                        max_value = num
                    if max_value > int(total_score / score_list[key] / 4):
                        max_value = int(total_score / score_list[key] / 4)
                equip_add_name = key
                equip_add_value = max_value
            new_have = "&".join(equip_have_split)
            new_equip_name = "{}={}={}".format(equip_have[0], new_have, equip_have[2])

        with open(f"data/bag/{uid}.txt", 'w') as f:
            json.dump(data, f, ensure_ascii=False, indent=4)
        await bag_reduce(uid, stone_name, stone_number)
        await bag_add(uid, new_equip_name, 1)
        txt = "\n【[{}]附魔完成！】{}".format(equip_name, txt0)

    elif len(equip_split) == 4:

        if random.random() <= stont_add_percent[0]:
            new_equip_name = "{}·{}++={}*{}&=".format(true_equip_name, equip_given, equip_add_name, equip_add_value)
            txt0 = "\n◈新增[{}+{}]".format(equip_add_name, equip_add_value)
            given_data[equip_given] = uid
            with open(f"data/冠名.txt", 'w', encoding='utf-8') as f:
                json.dump(given_data, f, ensure_ascii=False)
            with open(f"data/bag/{uid}.txt", 'w') as f:
                json.dump(data, f, ensure_ascii=False, indent=4)
            await bag_reduce(uid, stone_name, stone_number)
            await bag_add(uid, new_equip_name, 1)
            txt = "\n【你冠名了[{}·{}]】{}".format(true_equip_name, equip_given, txt0)

    if if_job:
        for job in jobs:
            if job["副职业"] == "锻造师":
                get_exp = int(20)
                if get_exp > job["精力"]:
                    get_exp = job["精力"]
                job["熟练度"] = int(job["熟练度"] + get_exp)
                job["精力"] = int(job["精力"] - get_exp)
                exp_list = [100, 400, 1500, 2500, 4500, 8000, 15000, 40000, 100000, 600000, 9999999999]
                job["熟练度上限"] = exp_list[job["等级"]]
                if job["熟练度"] >= job["熟练度上限"]:
                    job["等级"] += 1
                    job["熟练度"] -= job["熟练度上限"]
                    job["熟练度上限"] = exp_list[job["等级"]]
                    energy_max = [200, 400, 600, 800, 1000, 1500, 2000, 3000, 4000, 5000, 0]
                    job["精力上限"] = energy_max[job["等级"]]
                    txt += "\n✨【{}】锻造等级提升！✨".format(play_name)
                await player_write(number, "副职业", None, jobs)

    await send_message(message, 0, 1, txt)
    return


async def help_do_enchant(message):
    if hasattr(message.author, 'member_openid'):
        number = message.author.member_openid
    elif hasattr(message.author, 'user_openid'):
        number = message.author.user_openid
    uid = await player_id(number)
    play_name = await player_name(uid)
    help_player = (message.content.split("附魔")[0]).split("委托")[1]
    try:
        help_player_uid = int(help_player)
        help_player_number = await player_number(help_player_uid)
    except ValueError:
        txt = "\n【委托uid错误！】".format(resolve_name)
        await send_message(message, 0, 1, txt)
        return

    try:
        jobs = await player_read(help_player_number, "副职业", None)
        if not any(job["副职业"] == "锻造师" for job in jobs):
            if_job = False
            txt = "\n【委托者非锻造师！】"
            await send_message(message, 0, 1, txt)
            return
        else:
            if_job = True
            job_level = int([job["等级"] for job in jobs if job["副职业"] == "锻造师"][0])
    except TypeError:
        txt = "\n【委托uid错误！】".format(resolve_name)
        await send_message(message, 0, 1, txt)
        return
    need_money = int(50 + job_level * 5)
    need_txt = await bag_enough(uid, "铜币", need_money)
    if "不够" in need_txt:
        txt = "\n【缺少委托费用[铜币]×{}】".format(need_txt.split("缺")[1])
        await send_message(message, 0, 1, txt)
        return
    whole_name = message.content.split("附魔")[1]
    equip_split = whole_name.split("*")
    if len(equip_split) < 3:
        txt = "\n【委托附魔格式错误！】\n示例：[委托1附魔木棍*白晶*1*拟名]"
        await send_message(message, 0, 1, txt)
        return
    elif len(equip_split) == 3 and "·" not in equip_split[0]:
        txt = "\n【委托附魔格式错误！】\n【装备未拟名！】\n示例：[委托1附魔木棍*白晶*1*拟名]"
        await send_message(message, 0, 1, txt)
        return
    elif len(equip_split) == 4 and "·" in equip_split[0]:
        txt = "\n【委托附魔格式错误！】\n【装备已冠名！】\n示例：[委托1附魔木棍·疾风*白晶*1]"
        await send_message(message, 0, 1, txt)
        return
    equip_name = equip_split[0]
    stone_name = equip_split[1]
    stone_number = int(equip_split[2])
    
    if len(equip_split) == 4:
        equip_given = equip_split[3]
        with open(f"data/冠名.txt", 'r') as f:
            given_data = json.load(f)
        if equip_given in given_data:
            txt = "\n【拟名重复！】\n示例：[委托1附魔木棍*白晶*1*拟名]".format(equip_name)
            await send_message(message, 0, 1, txt)
            return
        if not equip_given.isalpha():
            txt = "\n【拟名不得含有空格字符！】\n示例：[委托1附魔木棍*白晶*1*拟名]".format(equip_name)
            await send_message(message, 0, 1, txt)
            return

    if "不够" in await bag_enough(uid, stone_name, stone_number):
        txt = "\n【你没有足够的[{}]！】".format(stone_name)
        await send_message(message, 0, 1, txt)
        return
    with open(f"data/bag/{uid}.txt", 'r') as f:
        data = json.load(f)
    have_equip = False
    for item in data['背包']:
        item_name = item['名称'].split("+")[0]
        true_equip_name = item_name.split("·")[0]
        if item_name == equip_name:
            whole_equip_name = item['名称']
            item['数量'] = int(item['数量']) - 1
            if item['数量'] <= 0:
                data['背包'].remove(item)
            have_equip = True
            break

    if not have_equip:
        txt = "\n【你背包中不存在[{}]】".format(equip_name)
        await send_message(message, 0, 1, txt)
        return

    if not os.path.exists(f"data/equipment/{true_equip_name}.txt"):
        txt = "\n【[{}]不可锻造！】".format(true_equip_name)
        await send_message(message, 0, 1, txt)
        return
    with open(f"data/equipment/{true_equip_name}.txt", 'r') as f:
        equip_data = json.load(f)
    total_score = 0
    score_list = {"最大生命": 1, "最大魔力": 1, "生命": 1, "魔力": 1, "物攻": 4, "魔攻": 4, "物防": 2, "魔防": 2, "命中": 2, "闪避": 2, "暴击": 2, "暴伤": 2, "暴免": 2, "暴抗": 2, "韧性": 2, "速度": 2, "体质": 120, "敏捷": 120, "力量": 120, "智力": 120, "物理减伤": 0, "魔法减伤": 0, "物理赠伤": 0, "魔法赠伤": 0}
    for key, value in equip_data["属性"].items():
        total_score += int(score_list[key] * value)

    if stone_name == "白晶":
        stone_term = {"生命": 100, "魔力": 100, "物攻": 25, "魔攻": 25, "物防": 25, "魔防": 25, "命中": 50, "闪避": 50, "暴击": 50, "暴伤": 50, "暴免": 50, "暴抗": 50, "韧性": 50, "速度": 50}
        stont_add_percent = [1, 0.25, 0, 0, 0, 0]
    if stone_name == "绿晶":
        stone_term = {"生命": 200, "魔力": 200, "物攻": 50, "魔攻": 50, "物防": 50, "魔防": 50, "命中": 100, "闪避": 100, "暴击": 100, "暴伤": 100, "暴免": 100, "暴抗": 100, "韧性": 100, "速度": 100}
        stont_add_percent = [1, 0.35, 0.05, 0, 0, 0]
    if stone_name == "劣等角质":
        stone_term = {"生命": 160, "物防": 40, "暴免": 80, "暴抗": 80, "体质": 2}
        stont_add_percent = [1, 0, 0, 0, 0, 0]
    if stone_name == "劣等硬刺":
        stone_term = {"物攻": 40, "暴击": 80, "暴伤": 80, "命中": 80, "力量": 2}
        stont_add_percent = [1, 0, 0, 0, 0, 0]
    if stone_name == "角质":
        stone_term = {"生命": 320, "物防": 80, "暴免": 160, "暴抗": 160, "体质": 4}
        stont_add_percent = [1, 0, 0, 0, 0, 0]
    if stone_name == "硬刺":
        stone_term = {"物攻": 80, "暴击": 160, "暴伤": 160, "命中": 160, "力量": 4}
        stont_add_percent = [1, 0, 0, 0, 0, 0]
    if stone_name == "上等角质":
        stone_term = {"生命": 600, "物防": 150, "暴免": 300, "暴抗": 300, "体质": 3}
        stont_add_percent = [1, 0, 0, 0, 0, 0]
    if stone_name == "上等硬刺":
        stone_term = {"物攻": 150, "暴击": 300, "暴伤": 300, "命中": 300, "力量": 3}
        stont_add_percent = [1, 0, 0, 0, 0, 0]
    if stone_name == "蓝晶":
        stone_term = {"生命": 400, "魔力": 400, "物攻": 100, "魔攻": 100, "物防": 100, "魔防": 100, "命中": 200, "闪避": 200, "暴击": 200, "暴伤": 200, "暴免": 200, "暴抗": 200, "韧性": 200, "速度": 200, "体质": 3, "敏捷": 3, "力量": 3, "智力": 3}
        stont_add_percent = [1, 0.5, 0.15, 0, 0, 0]
    if stone_name == "紫晶":
        stone_term = {"生命": 800, "魔力": 800, "物攻": 200, "魔攻": 200, "物防": 200, "魔防": 200, "命中": 400, "闪避": 400, "暴击": 400, "暴伤": 400, "暴免": 400, "暴抗": 400, "韧性": 400, "速度": 400, "体质": 6, "敏捷": 6, "力量": 6, "智力": 6}
        stont_add_percent = [1, 0.75, 0.4, 0.05, 0, 0]
    if stone_name == "金晶":
        stone_term = {"生命": 1600, "魔力": 1600, "物攻": 400, "魔攻": 400, "物防": 400, "魔防": 400, "命中": 800, "闪避": 800, "暴击": 800, "暴伤": 800, "暴免": 800, "暴抗": 800, "韧性": 800, "速度": 800, "体质": 12, "敏捷": 12, "力量": 12, "智力": 12}
        stont_add_percent = [1, 1, 0.6, 0.15, 0, 0]
    if stone_name == "红晶":
        stone_term = {"生命": 3200, "魔力": 3200, "物攻": 800, "魔攻": 800, "物防": 800, "魔防": 800, "命中": 1600, "闪避": 1600, "暴击": 1600, "暴伤": 1600, "暴免": 1600, "暴抗": 1600, "韧性": 1600, "速度": 1600, "体质": 25, "敏捷": 25, "力量": 25, "智力": 25}
        stont_add_percent = [1, 1, 0.75, 0.25, 0.03, 0]
    if stone_name == "彩晶":
        stone_term = {"生命": 10000, "魔力": 10000, "物攻": 2500, "魔攻": 2500, "物防": 2500, "魔防": 2500, "命中": 5000, "闪避": 5000, "暴击": 5000, "暴伤": 5000, "暴免": 5000, "暴抗": 5000, "韧性": 5000, "速度": 5000, "体质": 80, "敏捷": 80, "力量": 80, "智力": 80}
        stont_add_percent = [1, 1, 1, 0.5, 0.1, 0]
    key, value = random.choice(list(stone_term.items()))
    max_value = 0
    for i in range(stone_number):
        num = int(random.randint(1, value) * (1 + 0.03 * job_level))
        if num > max_value:
            max_value = num
        if max_value > int(total_score / score_list[key] / 4):
            max_value = int(total_score / score_list[key] / 4)

    equip_add_name = key
    equip_add_value = max_value


    if len(equip_split) == 3:
        equip_have = whole_equip_name.split("=")
        if len(equip_have) != 3:
            txt = "\n【装备数据错误！】"
            await send_message(message, 0, 1, txt)
            return
        equip_have_split = equip_have[1].split("&")
        equip_have_number = len(equip_have_split)
        equip_add_percent = stont_add_percent[equip_have_number - 1]
        if random.random() <= equip_add_percent:
            for random_num in range(1, equip_have_number):
                txt0 = "\n◈[{}+{}]".format((equip_have_split[random_num - 1].split("*"))[0], (equip_have_split[random_num - 1].split("*"))[1])
            new_equip_name = "{}={}{}*{}&={}".format(equip_have[0], equip_have[1], equip_add_name, equip_add_value, equip_have[2])
            txt0 += "\n◈新增[{}+{}]".format(equip_add_name, equip_add_value)
        else:
            txt0 = ""
            for random_num in range(1, equip_have_number):
                txt0 += "\n◈[{}+{}]➡︎[{}+{}]".format((equip_have_split[random_num - 1].split("*"))[0], (equip_have_split[random_num - 1].split("*"))[1], equip_add_name, equip_add_value)
                equip_have_split[random_num - 1] = "{}*{}".format(equip_add_name, equip_add_value)
                key, value = random.choice(list(stone_term.items()))
                max_value = 0
                for i in range(stone_number):
                    num = int(random.randint(1, value) * (1 + 0.03 * job_level))
                    if num > max_value:
                        max_value = num
                    if max_value > int(total_score / score_list[key] / 4):
                        max_value = int(total_score / score_list[key] / 4)
                equip_add_name = key
                equip_add_value = max_value
            new_have = "&".join(equip_have_split)
            new_equip_name = "{}={}={}".format(equip_have[0], new_have, equip_have[2])

        with open(f"data/bag/{uid}.txt", 'w') as f:
            json.dump(data, f, ensure_ascii=False, indent=4)
        await bag_reduce(uid, stone_name, stone_number)
        await bag_reduce(uid, "铜币", need_money)
        await bag_add(help_player_uid, "铜币", need_money)
        await bag_add(uid, new_equip_name, 1)
        txt = "\n【委托花费[{}]铜币】\n【[{}]附魔完成！】{}".format(need_money, equip_name, txt0)

    elif len(equip_split) == 4:

        if random.random() <= stont_add_percent[0]:
            new_equip_name = "{}·{}++={}*{}&=".format(true_equip_name, equip_given, equip_add_name, equip_add_value)
            txt0 = "\n◈新增[{}+{}]".format(equip_add_name, equip_add_value)
            given_data[equip_given] = uid
            with open(f"data/冠名.txt", 'w', encoding='utf-8') as f:
                json.dump(given_data, f, ensure_ascii=False)
            with open(f"data/bag/{uid}.txt", 'w') as f:
                json.dump(data, f, ensure_ascii=False, indent=4)
            await bag_reduce(uid, stone_name, stone_number)
            await bag_reduce(uid, "铜币", need_money)
            await bag_add(help_player_uid, "铜币", need_money)
            await bag_add(uid, new_equip_name, 1)
            txt = "\n【委托花费[{}]铜币】\n【冠名了[{}·{}]】{}".format(need_money, true_equip_name, equip_given, txt0)

    if if_job:
        for job in jobs:
            if job["副职业"] == "锻造师":
                get_exp = int(20)
                if get_exp > job["精力"]:
                    get_exp = job["精力"]
                job["熟练度"] = int(job["熟练度"] + get_exp)
                job["精力"] = int(job["精力"] - get_exp)
                exp_list = [100, 400, 1500, 2500, 4500, 8000, 15000, 40000, 100000, 600000, 9999999999]
                job["熟练度上限"] = exp_list[job["等级"]]
                if job["熟练度"] >= job["熟练度上限"]:
                    job["等级"] += 1
                    job["熟练度"] -= job["熟练度上限"]
                    job["熟练度上限"] = exp_list[job["等级"]]
                    energy_max = [200, 400, 600, 800, 1000, 1500, 2000, 3000, 4000, 5000, 0]
                    job["精力上限"] = energy_max[job["等级"]]
                await player_write(help_player_number, "副职业", None, jobs)

    await send_message(message, 0, 1, txt)
    return


        


async def do_reinforce(message):
    return
